Skip to content

Adds Variable Shadowing Rule#6568

Open
nadeemnali wants to merge 14 commits intorealm:mainfrom
nadeemnali:feature/variable-shadowing-rule
Open

Adds Variable Shadowing Rule#6568
nadeemnali wants to merge 14 commits intorealm:mainfrom
nadeemnali:feature/variable-shadowing-rule

Conversation

@nadeemnali
Copy link
Copy Markdown
Contributor

@nadeemnali nadeemnali commented Mar 30, 2026

Summary

Adds a new variable_shadowing rule that detects when a variable declaration shadows an identifier from an outer scope.

Changes

  • New Rule: VariableShadowingRule.swift - flags variable declarations that shadow outer scope identifiers
  • Registration: Added to BuiltInRules.swift
  • Tests: Added generated tests in GeneratedTests_10.swift
  • Configuration: Updated default_rule_configurations.yml
  • Documentation: Updated CHANGELOG.md

Example

var outer: String = "hello"
func test() {
    let outer = "world"  // ❌ Violates rule
}

Resolves #6228

@SwiftLintBot
Copy link
Copy Markdown

SwiftLintBot commented Mar 30, 2026

16308 Warnings
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:143:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:144:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:145:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:146:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:147:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:170:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:171:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:172:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:188:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:189:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:221:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:236:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/PanelWindowController.swift:263:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/Settings panels/NowPlayingViewController.swift:243:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/Settings panels/NowPlayingViewController.swift:246:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/Settings panels/SourcesViewController.swift:194:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/Settings panels/SourcesViewController.swift:207:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/VideosViewController.swift:203:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/VideosViewController.swift:210:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/VideosViewController.swift:417:17: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/VideosViewController.swift:506:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/VideosViewController.swift:572:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/VideosViewController.swift:574:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Resources/MainUI/VideosViewController.swift:735:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Music/Music.swift:101:28: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Music/Music.swift:104:28: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Music/Music.swift:107:28: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/AerialVideo.swift:171:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/TimeMachine.swift:33:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoLoader.swift:60:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoLoader.swift:104:17: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoLoader.swift:105:17: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoLoader.swift:177:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoDownload.swift:213:21: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoDownload.swift:233:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/PoiStringProvider.swift:132:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Thumbnails.swift:137:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Extensions/DispatchQueue+Extension.swift:16:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Cache.swift:177:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Cache.swift:260:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Cache.swift:354:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Cache.swift:689:17: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/Cache.swift:715:21: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoCache.swift:151:27: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoCache.swift:196:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoCache.swift:223:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoCache.swift:223:67: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoCache.swift:290:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoCache.swift:302:17: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoCache.swift:328:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoCache.swift:357:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Cache/VideoCache.swift:366:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/API/GeoCoding.swift:93:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/API/Forecast.swift:238:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Aerial.swift:31:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Aerial.swift:33:23: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/SourceList.swift:213:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/SourceList.swift:221:27: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/Source.swift:198:25: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Sources/Source.swift:201:25: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/API/OpenWeather.swift:266:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/API/OneCall.swift:275:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Models/Downloads/DownloadManager.swift:166:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/PrefPanel/CheckCellView.swift:42:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Controllers/CustomVideoController.swift:494:17: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/PrefPanel/VideoViewItem.swift:21:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/PrefPanel/VideoViewItem.swift:24:28: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/Music/ArtworkLayer.swift:27:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/Music/ArtworkLayer.swift:48:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/LocationLayer.swift:94:21: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/LocationLayer.swift:96:21: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/LocationLayer.swift:97:21: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/MessageLayer.swift:44:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/MessageLayer.swift:61:28: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/MessageLayer.swift:82:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/MessageLayer.swift:118:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/Weather/ConditionSymbolLayer.swift:103:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/Weather/ConditionSymbolLayer.swift:142:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/Weather/ConditionSymbolLayer.swift:213:23: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/Weather/WeatherLayer.swift:117:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Layers/Weather/WeatherLayer.swift:127:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/Sources/ActionCellView.swift:16:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:323:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:367:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:437:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:523:32: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:543:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:566:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:566:37: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:604:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:670:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:701:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:743:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:754:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:767:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Aerial: /Aerial/Source/Views/AerialView.swift:786:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/ParameterEncoder.swift:50:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/ParameterEncoder.swift:59:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/ParameterEncoder.swift:77:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/ParameterEncoder.swift:161:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Example/Source/DetailViewController.swift:75:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Example/Source/DetailViewController.swift:88:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Example/Source/DetailViewController.swift:94:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Example/Source/DetailViewController.swift:109:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Example/Source/DetailViewController.swift:113:23: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Example/Source/MasterViewController.swift:54:17: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/ParameterEncoding.swift:166:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/ParameterEncoding.swift:200:29: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/ParameterEncoding.swift:204:25: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/ParameterEncoding.swift:278:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/ParameterEncoding.swift:310:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Session.swift:215:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Session.swift:1173:28: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/DownloadRequest.swift:279:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/DownloadRequest.swift:403:32: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/DownloadRequest.swift:413:29: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/DownloadRequest.swift:415:29: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/WebSocketRequest.swift:289:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/WebSocketRequest.swift:490:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/UploadRequest.swift:111:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/UploadRequest.swift:135:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/UploadRequest.swift:152:17: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Features/OfflineRetrier.swift:40:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Features/OfflineRetrier.swift:42:23: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/HTTPHeaders.swift:101:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Response.swift:432:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/SessionDelegate.swift:238:19: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/DataRequest.swift:284:32: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/DataRequest.swift:294:29: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/DataRequest.swift:296:29: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:498:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:524:33: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:524:44: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:549:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:599:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:707:23: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:733:23: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:754:23: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:780:13: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:925:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:950:20: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:971:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:999:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:1026:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Core/Request.swift:1055:24: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Features/MultipartFormData.swift:321:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Features/MultipartFormData.swift:346:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Features/MultipartFormData.swift:516:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Features/MultipartFormData.swift:519:16: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ This PR introduced a violation in Alamofire: /Source/Features/CachedResponseHandler.swift:87:17: Warning: Do not shadow variables declared in outer scopes (variable_shadowing)
⚠️ Danger found 16308 violations with this PR. Due to GitHub's max issue comment size, the number shown has been truncated to 150.
19 Messages
📖 Building this branch resulted in a binary size of 27525.07 KiB vs 27476.09 KiB when built on main (0% larger).
📖 Linting Aerial with this PR took 0.81 s vs 0.82 s on main (1% faster).
📖 Linting Alamofire with this PR took 1.05 s vs 1.07 s on main (1% faster).
📖 Linting Brave with this PR took 7.2 s vs 7.19 s on main (0% slower).
📖 Linting DuckDuckGo with this PR took 27.83 s vs 27.73 s on main (0% slower).
📖 Linting Firefox with this PR took 12.16 s vs 12.08 s on main (0% slower).
📖 Linting Kickstarter with this PR took 8.4 s vs 8.35 s on main (0% slower).
📖 Linting Moya with this PR took 0.5 s vs 0.43 s on main (16% slower).
📖 Linting NetNewsWire with this PR took 2.61 s vs 2.58 s on main (1% slower).
📖 Linting Nimble with this PR took 0.68 s vs 0.69 s on main (1% faster).
📖 Linting PocketCasts with this PR took 7.9 s vs 7.71 s on main (2% slower).
📖 Linting Quick with this PR took 0.48 s vs 0.43 s on main (11% slower).
📖 Linting Realm with this PR took 3.02 s vs 3.01 s on main (0% slower).
📖 Linting Sourcery with this PR took 1.89 s vs 1.9 s on main (0% faster).
📖 Linting Swift with this PR took 4.67 s vs 4.66 s on main (0% slower).
📖 Linting SwiftLintPerformanceTests with this PR took 0.36 s vs 0.33 s on main (9% slower).
📖 Linting VLC with this PR took 1.28 s vs 1.23 s on main (4% slower).
📖 Linting Wire with this PR took 18.84 s vs 18.74 s on main (0% slower).
📖 Linting WordPress with this PR took 12.76 s vs 12.67 s on main (0% slower).

Generated by 🚫 Danger

Copy link
Copy Markdown
Collaborator

@SimplyDanny SimplyDanny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! Glad to see that DeclaredIdentifiersTrackingVisitor is used for more advanced rules.

print(outer)
}
"""),
]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a few more example involving properties, local variables, parameters, functions, tuples, optional bindings, ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Examples added for all the use cases

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

var a = 1
if let a = b {}
var i = 1
for i in list {}
struct S {
  var a = 1
  var b: Int {
    let a = 2
    return a
  }
}
var a = 1
func a(a: Int) {} // Should we trigger for the function name and/or the parameter (optionally)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for highlighting, i have added additional triggering examples, expanding the triggering examples

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var a = 1
func a(a: Int) {} // Should we trigger for the function name and/or the parameter (optionally)?

Triggering for parameters is optional, but the current behavior (not triggering) is standard and user-friendly. If you want to add an option to control this, I can add a configuration flag (e.g., ignoreParameters: true/false).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for highlighting, i have added additional triggering examples, expanding the triggering examples

Sure? I can't find them.

Triggering for parameters is optional, but the current behavior (not triggering) is standard and user-friendly. If you want to add an option to control this, I can add a configuration flag (e.g., ignoreParameters: true/false).

I'd prefer an option for that as I think some would like that. However, I leave it open to you to implement it or ignore it for now. In the latter case, this can be a follow-up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for highlighting, i have added additional triggering examples, expanding the triggering examples

Sure? I can't find them.

Apologies, didn't push it yet.

Triggering for parameters is optional, but the current behavior (not triggering) is standard and user-friendly. If you want to add an option to control this, I can add a configuration flag (e.g., ignoreParameters: true/false).

I'd prefer an option for that as I think some would like that. However, I leave it open to you to implement it or ignore it for now. In the latter case, this can be a follow-up.

Yes, i can look into this, will tag you once all the changes are pushed

Copy link
Copy Markdown
Contributor Author

@nadeemnali nadeemnali Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SimplyDanny, I have updated the rules with configuration and also added relevent examples, so all changes are pushed now

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still missing

struct S {
  var a = 1
  var b: Int {
    let a = 2
    return a
  }
}

And like if expressions, we can also have while let a = ... {}
and guard let a = ... else {}.

print(outer)
}
"""),
]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

var a = 1
if let a = b {}
var i = 1
for i in list {}
struct S {
  var a = 1
  var b: Int {
    let a = 2
    return a
  }
}
var a = 1
func a(a: Int) {} // Should we trigger for the function name and/or the parameter (optionally)?

@nadeemnali nadeemnali force-pushed the feature/variable-shadowing-rule branch 3 times, most recently from 3553d5d to eb602f2 Compare April 8, 2026 11:12
severity: warning
ignore_parameters: true
meta:
opt-in: false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule should be opt-in.

print(outer)
}
"""),
]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still missing

struct S {
  var a = 1
  var b: Int {
    let a = 2
    return a
  }
}

And like if expressions, we can also have while let a = ... {}
and guard let a = ... else {}.

override func visit(_ node: VariableDeclSyntax) -> SyntaxVisitorContinueKind {
if node.parent?.is(MemberBlockItemSyntax.self) == false {
node.bindings.forEach { binding in
checkForShadowing(in: binding.pattern)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test case fails if checkForBindingShadowing is used here. Is checkForShadowing really necessary? I actually doubt it. If it is, we need an example.

import TestHelpers
import XCTest

final class VariableShadowingRuleTests: SwiftLintTestCase {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't needed. You already check the option in the rule's examples.


/// Checks all scope levels including the current one. Used for parameter checking
/// since parameters are declared into a child scope, not the current one.
private func isShadowingAnyScope(_ identifier: String) -> Bool {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might not need this anymore once #6589 is merged.

@nadeemnali nadeemnali force-pushed the feature/variable-shadowing-rule branch from 5bcb7bf to fd51bd2 Compare April 10, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning for local variable shadowing

3 participants